package com.wzt.base.service.impl;

import com.wzt.base.service.IFastDfsService;
import com.wzt.base.util.FastdfsUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class FastDfsServiceImpl implements IFastDfsService {
    @Value("${fastdfs.url}")
    public String fastDfsUrl;

    /**
     * 上传文件字节数组及扩展名
     * @param bytes
     * @param extension
     * @return
     */
    @Override
    public String uploadFile(byte[] bytes, String extension) {
        return fastDfsUrl+ FastdfsUtil.upload(bytes,extension);
    }

    /**
     * 删除文件，传入文件在FastDFS中的路径，首先需要切除http://115.159.217.249:8888
     * @param path
     */
    @Override
    public void deleteFile(String path) {
        // path:   http://115.159.217.249:8888/group1/M00/00/00/rBEAA2MVmliAWdWWAACLuUIEKsg899.jpg
        path = path.substring(fastDfsUrl.length());
        FastdfsUtil.delete(path);
    }
}
